package com.enzoism.springboot.dive.mock;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 模拟数据库进行数据交易(单例类)
 */
@Service
public class MockDataSourceService {
    @Autowired
    MockDataSource mockDataSource;

    @Async
    public void requestRedisLockResult() {
        int taskNum = 100;
        ExecutorService executorService = Executors.newFixedThreadPool(taskNum);
        for (int i = 0; i < taskNum; i++) {
            executorService.submit(new MockDataSourceRunnable());
        }
    }
}
